﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Text;

using TribesPSO;

namespace TribesPSOTest.NUnit
{
    public class SearchSpace_Accessor<TParticle> where TParticle : Particle
    {
        SearchSpace<TParticle> searchSpace;

        public SearchSpace_Accessor(SearchSpace<TParticle> searchSpace)
        {
            this.searchSpace = searchSpace;
        }

        public Particle GenerateParticleAtPosition(EuclidianVector position)
        {
            return typeof(SearchSpace<TParticle>)
                .InvokeMember(
                    "GenerateParticleAtPosition"
                    , BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod
                    , null
                    , searchSpace
                    , new object[] { position })
                as Particle;
        }

        public Particle GenerateNewParticle()
        {
            return typeof(SearchSpace<TParticle>)
                .InvokeMember(
                    "GenerateNewParticle"
                    , BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod
                    , null
                    , searchSpace
                    , null)
                as Particle;
        }

        public IEnumerable<Particle> GenerateNewParticle(int numberToGenerate)
        {
            return typeof(SearchSpace<TParticle>)
                .InvokeMember(
                    "GenerateNewParticle"
                    , BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod
                    , null
                    , searchSpace
                    , new object[] { numberToGenerate })
                as IEnumerable<Particle>;
        }

        public EuclidianVector GeneratePosition()
        {
            return typeof(SearchSpace<TParticle>)
                .InvokeMember(
                    "GeneratePosition"
                    , BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod
                    , null
                    , searchSpace
                    , null)
                as EuclidianVector;
        }
    }
}
